//
//  GQHPushController.m
//  Xanthium
//
//  Created by GuanQinghao on 19/05/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHPushController.h"
#import "GQHHeader.h"
#import "GQHPushView.h"

@interface GQHPushController () {
    
#pragma mark Data
    
#pragma mark View
    /// 自定义根视图
    GQHPushView *rootView;
}

@end


@implementation GQHPushController

#pragma mark --Lifecycle
- (void)loadView {
    DLog();
    rootView = [[GQHPushView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.view = rootView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    DLog();
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    DLog();
    (self.isGoods) ? (self.qh_titleLabel.text = @"货源发布成功") : (self.qh_titleLabel.text = @"空车发布成功");
    [self.qh_rightButton setTitle:@"分享" forState:UIControlStateNormal];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self.qh_leftButton setImage:nil forState:UIControlStateNormal];
    [self.qh_leftButton setTitle:@"首页" forState:UIControlStateNormal];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    DLog();
    
}

#pragma mark --Delegate

#pragma mark --TargetMethod
- (void)qh_clickedLeftButton:(UIButton *)sender {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)qh_clickedRightButton:(UIButton *)sender {
    
    [self yy_UMShare];
}
#pragma mark --PrivateMethod
//  友盟分享
- (void)yy_UMShare
{
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_QQ)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        [self UMShareToPlatform:platformType];
    }];
}

- (void)UMShareToPlatform:(UMSocialPlatformType)platformType
{
    NSString *URLString = nil;
    if (self.isGoods)
    {
        URLString = [[NSString qh_APIURLString] stringByAppendingString:[NSString stringWithFormat:@"/share/viewGoodSources?id=%@", self.dataDic[@"sourcesId"]]];
    }
    else
    {
        URLString = [[NSString qh_APIURLString] stringByAppendingString:[NSString stringWithFormat:@"/share/viewCarSource?id=%@", self.dataDic[@"sourcesId"]]];
    }
    
    
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:self.dataDic[@"title"] descr:self.dataDic[@"msg"] thumImage:[UIImage imageNamed:@"logoiPhone"]];
    //设置网页地址
    shareObject.webpageUrl = URLString;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error)
     {
         if (error)
         {
             DLog(@"调用失败%@",error);
         }
         else
         {
             DLog(@"分享成功");
         }
     }];
}

#pragma mark --Setter

#pragma mark --Getter

#pragma mark --View

@end
